﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>驾驶证记分查询</title>
		<meta charset='UTF-8'>
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<meta content="telephone=no,email=no" name="format-detection" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui" />
		<link href="../css/alipay/alipay.css" type="text/css" rel="stylesheet" />
		<link href="../css/alipay/amui-demo_files/toast.css" type="text/css" rel="stylesheet" />
		<link href="../css/alipay/button.css" type="text/css" rel="stylesheet" />
		<link href="../css/alipay/amui-demo_files/dialog.css" type="text/css" rel="stylesheet" />
		<link href="../css/alipay/amui-demo_files/button-group.css" type="text/css" rel="stylesheet" />
		<link href="../css/main.css" type="text/css" rel="stylesheet" />
		<link href="../css/dialog.css" type="text/css" rel="stylesheet" />
		<script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" src="../js/extensions/base.js"></script>
		<script type="text/javascript" src="../css/alipay/amui-demo_files/amui.js"></script>
		<style>
		.am-list:not([am-version]){padding:0px;}
			.ui-block-a,
			.ui-block-b,
			.ui-block-c,
			.ui-block-d {
				padding: 10px 0 10px 0;
				text-align: center;
			}
			
			.ui-block-a img,
			.ui-block-b img,
			.ui-block-c img,
			.ui-block-d img {
				width: 43%;
				padding-top: 10%;
			}
			
			.am-button {
				padding-LEFT: 15PX;
			}
			.am-list:not([am-version]) .am-list-footer{margin:9px; font-size: 12px;}
		</style>
		<script type="text/javascript">
			$(function(){
				/*$("#dialogbut").click(function(){
					$(".mask").show();
					$(".demo-content").show();
				});*/

				$(".am-dialog-button").click(function(){
					$(".mask").hide();
					$(".demo-content").hide();
				});

			})
		</script>
	</head>

	<body>
	<div class="mask" style="display: none;"></div>
	<div class="demo-content"  style="display: none;">
		<div class="demo-mobile">
			<div class="am-dialog show" style="z-index: 10001;">
				<div class="am-dialog-wrap">
					<div class="am-dialog-body">
						<p id="warn" class="am-dialog-brief"></p>
					</div>
					<div class="am-dialog-footer">
						<a class="am-dialog-button">取消</a>
						<a class="am-dialog-button">确定</a>
					</div>
				</div>
			</div>
		</div>
	</div>
		<div data-role="page">
			<div data-role="content" style="background-color:#EFEFF4;padding-top:15PX;">
				<div class="am-list am-list-5lb" am-mode="flat form">
					<div class="am-list-body">
						<div class="am-toast" id="toast">
							<div class="am-toast-text">
								<span class="am-toast-icon am-icon" am-mode="toast-loading"></span> 正在查询...
							</div>
						</div>

						<div class="am-search-input">
							<div class="am-list" am-mode="flat chip form">
								<div class="am-list-body">
									<div class="am-list-item am-input-autoclear">
										<div class="am-list-label">驾驶证编号</div>
										<div class="am-list-control">
											<input type="text" id="inputDL" placeholder="请输入驾驶证编号" value="">
										</div>
										<div class="am-list-clear"><i class="am-icon-clear am-icon" am-mode="clear"></i></div>
									</div>
									<div class="am-list-item am-input-autoclear">
										<div class="am-list-label">档案编号</div>
										<div class="am-list-control">
											<input type="text" id="inputFN" placeholder="请输入档案编号" value="">
										</div>
										<div class="am-list-clear"><i class="am-icon-clear am-icon" am-mode="clear"></i></div>
										<div class="am-list-thumb"><i class="am-icon" am-mode="form-camera"></i></div>
									</div>
								</div>
							</div>

							<div class="am-list-footer" style="padding-top:5px;">注：目前仅支持吉林省本地车辆的违法查询</div>
							<div style="padding-left:15px;padding-right:15px;margin-top:15PX;">
								<input type="hidden" id="action" name="action" value="" />
								<input type="hidden" id="command" name="command" value="" />
								<button id="searchButton" type="button" class="am-button" am-mode="blue disabled">查询</button>
								<button id="resultButton" type="button" class="am-button" am-mode="blue disabled" style="display: none;">查询结果</button>
							</div>
						</div>

					</div>
				</div>
				<div id="fuwu" style="display: block;font-family:STHeitiSC  ;font-size: 12px; margin-bottom: 15px; margin-left: 0px; width: 100%; text-align: center; position: absolute; bottom: 0px;z-index:-1;">
					<div class="am-agreement am-ft-gray am-ft-sm">
						<p>
							本服务由吉林省公安厅<br />江苏欧索软件有限公司提供支持
						</p>
					</div>
				</div>
			</div>
		</div>
		<script>
			var secs = 60;
			$(function() {
				$("#toast").hide();
				window.setInterval("checkButtonState()", 200);
				$("#searchButton").click(function() {
					var jtglywdxsfzhm = $("#inputDL").val();
					var dabh = $("#inputFN").val();
					var fnFormat = /[a-z_A-Z_0-9]{12}/;
					var secformet = "请输入12位档案编号";
					if (!fnFormat.test(dabh)) {
						$("#warn").html(secformet);
						$(".mask").show();
						$(".demo-content").show();
					} else {
						search();
					}
				});
			});

			function checkButtonState() {
				if ($("#inputDL").val() && $("#inputFN").val())
					$("#searchButton").attr("am-mode", "blue");
				else
					$("#searchButton").attr("am-mode", "blue disabled");
			}

			function search() {
				if (CheckIDCard()) {
					$("#toast").show();
					var jtglywdxsfzhm = $("#inputDL").val();
					var dabh = $("#inputFN").val();
					$.ajax({
						url: '../../../api/cityservice/driver/points',
						type: 'post',
						data: {
							"jtglywdxsfzhm": jtglywdxsfzhm,
							"dabh": dabh
						},
						success: function(resp) {
							if (resp && resp.succ && resp.statusCode == 100102) {
								//查询条件提交，等待查询结果
								$("#action").val("").val(resp.data.action);
								$("#command").val("").val(resp.data.command);
								$("#searchButton").hide();
								for (var i = 1; i <= secs; i++) {
									window.setTimeout("update(" + i + ")", i * 1000);
								}
								$("#resultButton").show();
							} else if (resp && resp.succ && resp.statusCode == 100101) {
								//查询条件已有查询结果，直接返回结果
								window.location.href = 'DriverScoreResult.html?jtglywdxsfzhm=' + jtglywdxsfzhm + '&dabh=' + dabh;
							} else {
								$("#warn").html(resp.msg);
								$(".mask").show();
								$(".demo-content").show();
							}
						},
						error: function() {
							$("#warn").html("查询失败!");
							$(".mask").show();
							$(".demo-content").show();
						},
						complete: function() {
							$("#toast").hide();
						}
					});
				}
			}

			function CheckIDCard() {
				var idCard = $("#inputDL").val();
				if (idCard.length == 18) {
					var regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
					if (regIdCard.test(idCard)) {
						var idCardWi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); //将前17位加权因子保存在数组里
						var idCardY = new Array(1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2);
						var idCardWiSum = 0;
						for (var i = 0; i < 17; i++) {
							idCardWiSum += idCard.substring(i, i + 1) * idCardWi[i];
						}
						var idCardMod = idCardWiSum % 11;
						var idCardLast = idCard.substring(17);
						if (idCardMod == 2) {
							if (idCardLast == "X" || idCardLast == "x") {
								return true;
							} else {
								$("#warn").html("驾驶证号码不正确！");
								$(".mask").show();
								$(".demo-content").show();
							}
						} else {
							//用计算出的验证码与最后一位身份证号码匹配，如果一致，说明通过，否则是无效的身份证号码
							if (idCardLast == idCardY[idCardMod]) {
								return true;
							} else {
								$("#warn").html("驾驶证号码不正确！");
								$(".mask").show();
								$(".demo-content").show();
							}
						}
					}
				} else if (idCard.length == 15) {
					isIDCard1 = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
					if (isIDCard1.test(idCard)) {
						return true;
					} else {
						$("#warn").html("驾驶证号码输入错误！");
						$(".mask").show();
						$(".demo-content").show();
					}
				} else {
					$("#warn").html("驾驶证格式不正确!");
					$(".mask").show();
					$(".demo-content").show();
				}
			}
			$("#resultButton").click(function() {
				var action = $("#action").val();
				var command = $("#command").val();
				var jtglywdxsfzhm = $("#inputDL").val();
				var dabh = $("#inputFN").val();
				$.ajax({
					url: '../../../api/cityservice/result/gain',
					type: 'post',
					data: {
						"action": action,
						"command": command
					},
					success: function(resp) {
						if (resp && resp.succ && resp.statusCode == 100101) {
							//查询条件已有查询结果，直接返回结果
							window.location.href = 'DriverScoreResult.html?jtglywdxsfzhm=' + jtglywdxsfzhm + '&dabh=' + dabh;
						} else {
							$("#warn").html(resp.msg);
							$(".mask").show();
							$(".demo-content").show();

							$("#inputDL").val("");
							$("#inputFN").val("");
							$("#searchButton").show();
							$("#resultButton").hide();
							$("#resultButton").attr("am-mode", "blue disabled");
						}
					},
					error: function() {
						$("#warn").html("查询结果失败!");
						$(".mask").show();
						$(".demo-content").show();
					}
				});
			});

			function update(num) {
				if (num == secs) {
					$("#resultButton").text("查询结果");
					$("#resultButton").attr("am-mode", "blue");
				} else {
					var printnr = secs - num;
					$("#resultButton").text(printnr + "秒后可查询结果");
				}
			}
		</script>
	</body>

</html>